﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Transform;

namespace HotelDAO.DAO
{
    /// <summary>
    /// This class is supported to custom query result.
    /// </summary>
    /// <typeparam name="T"></typeparam>
    public class CustomResultTransformer<T> : IResultTransformer
    {
        #region Variables
        /// <summary>
        /// Transformation.
        /// </summary>
        private Func<object[], string[], T> _transformation;
        #endregion
        #region Constructors
        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="transformation"></param>
        public CustomResultTransformer(Func<object[], string[], T> transformation)
        {
            this._transformation = transformation;
        }

        /// <summary>
        /// Constructor.
        /// </summary>
        /// <param name="transformation"></param>
        public CustomResultTransformer(Func<object[], T> transformation)
        {
            this._transformation = (tuple, aliases) => transformation(tuple);
        }
        #endregion
        #region Methods
        /// <summary>
        /// Transform list.
        /// </summary>
        /// <param name="collection"></param>
        /// <returns></returns>
        public IList TransformList(IList collection)
        {
            return collection;
        }

        /// <summary>
        /// Transform tuple.
        /// </summary>
        /// <param name="tuple"></param>
        /// <param name="aliases"></param>
        /// <returns></returns>
        public object TransformTuple(object[] tuple, string[] aliases)
        {
            return _transformation(tuple, aliases);
        }
        #endregion
    }
}
